#ifndef __CONTROLLED_OBJECT_H__
#define __CONTROLLED_OBJECT_H__

#pragma once

#include "RenderingConfig.h"

namespace Nezha
{
	class Controller;

	class NEZHA_ENGINE_ENTRY ControlledObject
	{
		friend class Controller;
	public:
		ControlledObject();
		virtual ~ControlledObject();

		virtual void notifyAffected(){}

	protected:
		virtual void onSetController(Controller* c) {}
	private:
		void _setController(Controller* c)
		{
			onSetController(c);
			mController = c;
		}

		Controller* mController;
	};

	class NEZHA_ENGINE_ENTRY Controller
	{
	public:
		virtual ~Controller(){}

		virtual void affect(float delta);

		void attachObject(ControlledObject* co);

		void detachObject(ControlledObject* co);

		void detachAll();

	protected:
		PArray<ControlledObject*> mControlledObjects;
	};

	typedef RefCountedPtr<Controller>::Default ControllerPtr;

	// just a controller container
	class NEZHA_ENGINE_ENTRY ContollerJoint
	{
	public:
		void update(float dt);

		void addController(Controller* c);

		void removeController(Controller* c);

		u32 getNumControllers() const
		{
			return mControllers.size();
		}

		Controller* getController(u32 i);

		void removeAll();
	private:
		PArray<Controller*> mControllers;
	};

}//end namespace Nezha

#endif //end __CONTROLLED_OBJECT_H__